import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:yt_devops/components/gaps.dart';
import 'package:yt_devops/components/log_utils.dart';
import 'package:yt_devops/components/yt_text_style.dart';
import 'package:yt_devops/pages/mine/user_manage/user_manager_user_detail/tree_expand.dart';

import '../../../../styles/styles.dart';

/**
 *
 * @Description TODO
 * @Author liuer
 * @CreateTime 2023年12月19日 15:55
 */
class TreeTopExpansionCard extends StatefulWidget {
  final String title;
  final Function(bool)? callBack; // 点击标题的回调
  final List<Widget>? contentWidget; // 折叠内容
  final double marginLeft;
  bool isSelected;
   TreeTopExpansionCard(
      {Key? key,

        required this.title,
        required this.contentWidget,
        this.marginLeft = 32,
        required this.isSelected,
        this.callBack,})
      : super(key: key);

  @override
  State<TreeTopExpansionCard> createState() => _TreeTopExpansionCardState();
}

class _TreeTopExpansionCardState extends State<TreeTopExpansionCard> {
  bool _isExpanded = false;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }
  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: const BoxDecoration(
        color: Colour.backgroundColor,

        borderRadius: BorderRadius.all(Radius.circular(6)),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisAlignment: MainAxisAlignment.start,
        children: <Widget>[
          GestureDetector(
            onTap: () {
              _isExpanded = !_isExpanded;
              if (mounted) {
                setState(() {});
              }

            },
            child: Container(
              height: 40,
              color: Colors.white,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                  SizedBox(width: widget.marginLeft),
                  GestureDetector(
                    child: Container(
                      padding: const EdgeInsets.only(
                          left: 16, top: 14, bottom: 14),
                      child: Image.asset(
                        _isExpanded
                            ?'assets/images/site_observer_down_arrow.png':'assets/images/site_observer_right_arrow.png',
                        height: 16,
                        width: 16,
                        fit: BoxFit.cover,
                        // color: widget.status == 2?Colours.redFF7F74Color:Colours.green8EFB7DColor,
                      ),
                    ),
                  ),
                  Container(
                    alignment: Alignment.center,
                    child: Text(
                      widget.title,
                      style: ytTextStyle(
                          fontSize: 14,
                          height: 1.1,
                          fontWeight: FontWeight.normal),
                    ),
                  ),
                  Gaps.hGap8,

                  Spacer(),
                  Container(
                    padding: const EdgeInsets.only(right: 6),
                    child: IconButton(
                      padding: EdgeInsets.zero,
                      iconSize: 20,
                      icon:widget.isSelected
                          ? const Icon(
                        Icons.check_circle,
                        color: Colour.primaryColor,
                      )
                          : const Icon(
                        Icons.circle_outlined,
                        color: Colour.diabledButtoBgColor,
                      ),
                      onPressed: () {
                        setState(() {
                          widget.isSelected = !widget.isSelected;
                        });
                        Log.d('isSelected==' + widget.isSelected.toString());
                        if(widget.callBack != null){
                          widget.callBack!(widget.isSelected);
                        }
                      },
                    ),
                  ),
                  Gaps.hGap8,

                ],
              ),
            ),
          ),
          Container(
            alignment: Alignment.centerLeft,
            // color: Colors.red,
            child: ExpansionCustom(
              initiallyExpanded: false,
              isExpanded: _isExpanded,
              padding: EdgeInsets.zero,
              children: <Widget>[
                Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  mainAxisAlignment: MainAxisAlignment.start,
                  children: widget.contentWidget ?? [Container()],
                )
              ],
            ),
          )
        ],
      ),
    );

  }
}
